package com.toutou.base.util

import android.content.Context

class DensityUtil {
    companion object {
        fun dip2px(context: Context, dp: Float): Int {
            return dip2px(dp)
        }
        fun dip2px(dp: Float): Int {
            ActivitiesManager.topActivity()?.let {
                val scale = it.resources.displayMetrics.density
                return (dp * scale + 0.5f).toInt()
            }
            return dp.toInt()
        }

        fun px2dp(px: Float): Int {
            ActivitiesManager.topActivity()?.let {
                val scale = it.resources.displayMetrics.density
                return (px / scale + 0.5f).toInt()
            }
            return px.toInt()
        }
    }
}